package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.UserVocAISituationDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserVocAISituationCommand;
import com.cskaoyan.wordmemorize.service.AIReadService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController


@RequestMapping("admin/voc/ai-read")
public class AIReadController {

    @Resource
    AIReadService aiReadService;

    @GetMapping("situation/list")
    public Result<PageDTO<UserVocAISituationDTO>> getAISituationList(PageRequest pageRequest) {
        PageDTO<UserVocAISituationDTO> aiSituationList = aiReadService.getAISituationList(pageRequest);
        return Result.ok(aiSituationList);
    }

    @PostMapping("situation")
    public Result<Void> addAISituation(@RequestBody UserVocAISituationCommand command) {
        aiReadService.addAISituation(command);
        return Result.ok();
    }

    @PutMapping("situation")
    public Result<Void> updateAISituation(@RequestBody UserVocAISituationCommand command) {
        aiReadService.updateAISituation(command);
        return Result.ok();
    }

    @DeleteMapping("option/{optionId}")
    public Result<Void> deleteAISituationOption(@PathVariable("optionId") Long optionId) {
        aiReadService.deleteAISituationOption(optionId);
        return Result.ok();
    }


    @DeleteMapping("situation/{situationId}")
    public Result<Void> deleteAISituation(@PathVariable("situationId") Long situationId) {
        aiReadService.deleteAISituation(situationId);
        return Result.ok();
    }

    @DeleteMapping("situation")
    public Result<Void> batchDeleteAISituationOption(@RequestBody BatchDeleteCommand command) {
        List<String> ids = command.getIds();
        List<Long> collect = ids.stream().map(Long::parseLong).collect(Collectors.toList());
        aiReadService.batchDeleteAISituationOption(collect);
        return Result.ok();
    }


}
